using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;

namespace Tequila.Phone.Interactivity
{
    /// <summary>
    /// Simple implementation of <see cref="TextBoxEnterKeyDownUpdateSourceTrigger{T}"/> using <see cref="TextBox"/> as associated object.
    /// </summary>
    public class TextBoxEnterKeyDownUpdateSourceTrigger : TextBoxEnterKeyDownUpdateSourceTrigger<TextBox>
    {

    }

    /// <summary>
    /// <see cref="EnterKeyDownUpdateSourceTrigger{T}"/> that updates Text property <see cref="Binding">bound</see> data source.
    /// </summary>
    /// <typeparam name="T">Implementation of <see cref="TextBox"/>.</typeparam>
    public class TextBoxEnterKeyDownUpdateSourceTrigger<T> : EnterKeyDownUpdateSourceTrigger<T>
        where T : TextBox
    {
        /// <summary>
        /// Triggers custom actions when Enter <see cref="Key">key</see> down event occured.
        /// </summary>
        protected override void Trigger()
        {
            var binding = AssociatedObject.GetBindingExpression(TextBox.TextProperty);

            if (binding != null)
            {
                binding.UpdateSource();
            }

            base.Trigger();
        }
    }
}